//
//  UIBarButtonItem+WRYHighlightButton.m
//  BaiSiBuJie
//
//  Created by wry on 16/4/25.
//  Copyright © 2016年 WRY. All rights reserved.
//

#import "UIBarButtonItem+WRYHighlightButton.h"

@implementation UIBarButtonItem (WRYHighlightButton)

+(UIBarButtonItem *)itemWithNormalImage:(UIImage *)norImage highlightImage:(UIImage*)clickImage target:(nullable id)target action:(nullable SEL)action
{
    UIButton *button=[UIButton buttonWithType:(UIButtonTypeCustom)];
    //添加监听
    [button addTarget:target action:action forControlEvents:(UIControlEventTouchDown)];
    
    UIBarButtonItem *item=[[UIBarButtonItem alloc]init];
    
    [button setImage:norImage forState:(UIControlStateNormal)];
    [button setImage:clickImage forState:(UIControlStateHighlighted)];
    [button sizeToFit];
    
// 把按钮包装成UIBarButtonItem，点击范围扩大，把按钮放在UIView,在把UIView包装成UIBarButtonItem
    UIView *v =[[UIView alloc]initWithFrame:button.frame];
    [v addSubview:button];
    item.customView=v;
    return item;
}

+(UIBarButtonItem *)itemWithNormalImage:(UIImage *)norImage selectImage:(UIImage*)selImage target:(nullable id)target action:(nullable SEL)action
{
    UIButton *button=[UIButton buttonWithType:(UIButtonTypeCustom)];
    //添加监听
    [button addTarget:target action:action forControlEvents:(UIControlEventTouchUpInside)];
    
    UIBarButtonItem *item=[[UIBarButtonItem alloc]init];
    
    [button setImage:norImage forState:(UIControlStateNormal)];
    [button setImage:selImage forState:(UIControlStateSelected)];
    
    [button sizeToFit];
    
    // 把按钮包装成UIBarButtonItem，点击范围扩大，把按钮放在UIView,在把UIView包装成UIBarButtonItem
    UIView *v =[[UIView alloc]initWithFrame:button.frame];
    [v addSubview:button];
    item.customView=v;
    return item;
}









@end
